#include "ustandard/ustandard_def.h"
int dir_read(const char* name)
{
    int ret = 0;

    DIR* dirp = opendir(name);
    printf("dirp=%p\n", dirp);
    assert(NULL != dirp);

    struct dirent entry;
    struct dirent* result = NULL;
    int retdir = 0;
    int idx = 0;
    printf("&entry=%p\n", &entry);

    while(1) {
        result = NULL;
        retdir = readdir_r(dirp, &entry, &result);
        if(0 != retdir) {
            printf("error.\n");
            break;
        }

        if(0 == retdir && NULL == result) {
            printf("finished.\n");
            break;
        }

        printf("entry[%d] , result=%p: \n"
                "\t%10s:%lu\n"
                "\t%10s:%d\n"
                "\t%10s:%d\n"
                "\t%10s:%s\n", 
                idx, result, 
                "d_off", 
                entry.d_off, 
                "d_reclen",
                entry.d_reclen,
                "d_type",
                entry.d_type,
                "d_name",
                entry.d_name);

        idx ++;
    }

    closedir(dirp);
    dirp = NULL;

    return ret;
}


int main(int argc, char* argv[])
{
    dir_read(argv[1]);

    return 0;
}
